<?php

namespace api\energy\common;

class Log
{
    /**
     * 写入日志
     *
     * @param string $fileName 文件名称
     * @param string $str 日志信息
     */
    public static function writeLog($fileName, $str)
    {
        $dir = __DIR__ . '/../request_log';
        if (!is_dir($dir)) {
            mkdir($dir, 0777, true);
        }
        if (count(explode('.', $fileName)) == 1) {
            $fileName = $fileName . '.log';
        }
        list($t1, $t2) = explode(' ', microtime());

        $writeStr = date('Y-m-d H:i:s', (int)$t2) . '.' . str_pad(bcmul($t1, '1000'), 3, '0', STR_PAD_LEFT) . ' ' . $str . PHP_EOL;
        file_put_contents($dir . '/' . $fileName, $writeStr, FILE_APPEND);
    }

}
